<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Racc::States - racc: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="../Object.html">Object</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Enumerable</span>
  </ul>
</div>

        
<div id="extends-section" class="nav-section">
  <h3>Extended With Modules</h3>

  <ul class="link-list">
    <li><span class="extend">Forwardable</span>
  </ul>
</div>

        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-addrel">#addrel</a>
    <li ><a href="#method-i-addsym">#addsym</a>
    <li ><a href="#method-i-check_useless">#check_useless</a>
    <li ><a href="#method-i-compute_dfa">#compute_dfa</a>
    <li ><a href="#method-i-compute_nfa">#compute_nfa</a>
    <li ><a href="#method-i-core_to_state">#core_to_state</a>
    <li ><a href="#method-i-create_tmap">#create_tmap</a>
    <li ><a href="#method-i-dfa">#dfa</a>
    <li ><a href="#method-i-digraph">#digraph</a>
    <li ><a href="#method-i-do_resolve_sr">#do_resolve_sr</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-each_index">#each_index</a>
    <li ><a href="#method-i-each_state">#each_state</a>
    <li ><a href="#method-i-each_t">#each_t</a>
    <li ><a href="#method-i-fingerprint">#fingerprint</a>
    <li ><a href="#method-i-generate_states">#generate_states</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-lookahead">#lookahead</a>
    <li ><a href="#method-i-n_rrconflicts">#n_rrconflicts</a>
    <li ><a href="#method-i-n_srconflicts">#n_srconflicts</a>
    <li ><a href="#method-i-nfa">#nfa</a>
    <li ><a href="#method-i-pack">#pack</a>
    <li ><a href="#method-i-print_atab">#print_atab</a>
    <li ><a href="#method-i-print_tab">#print_tab</a>
    <li ><a href="#method-i-print_tab_i">#print_tab_i</a>
    <li ><a href="#method-i-printb">#printb</a>
    <li ><a href="#method-i-record_path">#record_path</a>
    <li ><a href="#method-i-resolve">#resolve</a>
    <li ><a href="#method-i-resolve_rr">#resolve_rr</a>
    <li ><a href="#method-i-resolve_sr">#resolve_sr</a>
    <li ><a href="#method-i-rrconflict_exist-3F">#rrconflict_exist?</a>
    <li ><a href="#method-i-set_accept">#set_accept</a>
    <li ><a href="#method-i-should_report_srconflict-3F">#should_report_srconflict?</a>
    <li ><a href="#method-i-size">#size</a>
    <li ><a href="#method-i-srconflict_exist-3F">#srconflict_exist?</a>
    <li ><a href="#method-i-state_transition_table">#state_transition_table</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-transpose">#transpose</a>
    <li ><a href="#method-i-traverse">#traverse</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Racc::States">
    <h1 id="class-Racc::States" class="class">
      class Racc::States
    </h1>

    <section class="description">
    
<p>A table of LALR states.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="ASSOC">ASSOC
          <dd>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-actions" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">actions</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
          <div id="attribute-i-grammar" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">grammar</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(grammar, debug_flags = DebugFlags.new)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">grammar</span>, <span class="ruby-identifier">debug_flags</span> = <span class="ruby-constant">DebugFlags</span>.<span class="ruby-identifier">new</span>)
  <span class="ruby-ivar">@grammar</span> = <span class="ruby-identifier">grammar</span>
  <span class="ruby-ivar">@symboltable</span> = <span class="ruby-identifier">grammar</span>.<span class="ruby-identifier">symboltable</span>
  <span class="ruby-ivar">@d_state</span> = <span class="ruby-identifier">debug_flags</span>.<span class="ruby-identifier">state</span>
  <span class="ruby-ivar">@d_la</span>    = <span class="ruby-identifier">debug_flags</span>.<span class="ruby-identifier">la</span>
  <span class="ruby-ivar">@d_prec</span>  = <span class="ruby-identifier">debug_flags</span>.<span class="ruby-identifier">prec</span>
  <span class="ruby-ivar">@states</span> = []
  <span class="ruby-ivar">@statecache</span> = {}
  <span class="ruby-ivar">@actions</span> = <span class="ruby-constant">ActionTable</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grammar</span>, <span class="ruby-keyword">self</span>)
  <span class="ruby-ivar">@nfa_computed</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@dfa_computed</span> = <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-5B-5D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">[]</span><span
                                class="method-args">(i)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="5B-5D-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 51</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]</span>(<span class="ruby-identifier">i</span>)
  <span class="ruby-ivar">@states</span>[<span class="ruby-identifier">i</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dfa" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">dfa</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>DFA (Deterministic Finite Automaton) Generation</p>

                              <div class="method-source-code" id="dfa-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 196</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dfa</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@dfa_computed</span>
  <span class="ruby-identifier">nfa</span>
  <span class="ruby-identifier">compute_dfa</span>
  <span class="ruby-ivar">@dfa_computed</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">each</span><span
                                class="method-args">(&amp;block)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="States.html#method-i-each_state">each_state</a>
                            </div>
                          </div>

                  <div id="method-i-each_index" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_index</span><span
                                class="method-args">(&amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="each_index-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 61</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_index</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">each_index</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_state" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_state</span><span
                                class="method-args">(&amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="each_state-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_state</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="States.html#method-i-each">each</a>
                            </div>

                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 45</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-string">&#39;#&lt;state table&gt;&#39;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="States.html#method-i-to_s">to_s</a>
                            </div>

                          </div>

                  <div id="method-i-n_rrconflicts" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">n_rrconflicts</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="n_rrconflicts-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 88</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">n_rrconflicts</span>
  <span class="ruby-ivar">@n_rrconflicts</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">inject</span>(<span class="ruby-value">0</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">sum</span>, <span class="ruby-identifier">st</span><span class="ruby-operator">|</span> <span class="ruby-identifier">sum</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">st</span>.<span class="ruby-identifier">n_rrconflicts</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-n_srconflicts" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">n_srconflicts</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="n_srconflicts-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 80</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">n_srconflicts</span>
  <span class="ruby-ivar">@n_srconflicts</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">inject</span>(<span class="ruby-value">0</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">sum</span>, <span class="ruby-identifier">st</span><span class="ruby-operator">|</span> <span class="ruby-identifier">sum</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">st</span>.<span class="ruby-identifier">n_srconflicts</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-nfa" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">nfa</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>NFA (Non-deterministic Finite Automaton) Computation</p>

                              <div class="method-source-code" id="nfa-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 102</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">nfa</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@nfa_computed</span>
  <span class="ruby-identifier">compute_nfa</span>
  <span class="ruby-ivar">@nfa_computed</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rrconflict_exist-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rrconflict_exist?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="rrconflict_exist-3F-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 84</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">rrconflict_exist?</span>
  <span class="ruby-identifier">n_rrconflicts</span>() <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-should_report_srconflict-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">should_report_srconflict?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="should_report_srconflict-3F-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">should_report_srconflict?</span>
  <span class="ruby-identifier">srconflict_exist?</span> <span class="ruby-keyword">and</span>
      (<span class="ruby-identifier">n_srconflicts</span>() <span class="ruby-operator">!=</span> <span class="ruby-ivar">@grammar</span>.<span class="ruby-identifier">n_expected_srconflicts</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-size" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">size</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="size-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 41</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">size</span>
  <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">size</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-srconflict_exist-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">srconflict_exist?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="srconflict_exist-3F-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 76</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">srconflict_exist?</span>
  <span class="ruby-identifier">n_srconflicts</span>() <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-state_transition_table" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">state_transition_table</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="state_transition_table-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 92</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">state_transition_table</span>
  <span class="ruby-ivar">@state_transition_table</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">StateTransitionTable</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">dfa</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="States.html#method-i-inspect">inspect</a>
                            </div>
                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-addrel" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">addrel</span><span
                                class="method-args">(tbl, i, item)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="addrel-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 317</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">addrel</span>(<span class="ruby-identifier">tbl</span>, <span class="ruby-identifier">i</span>, <span class="ruby-identifier">item</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span> = <span class="ruby-identifier">tbl</span>[<span class="ruby-identifier">i</span>]
    <span class="ruby-identifier">a</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">item</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">tbl</span>[<span class="ruby-identifier">i</span>] = [<span class="ruby-identifier">item</span>]
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-addsym" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">addsym</span><span
                                class="method-args">(table, sym, ptr)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="addsym-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 154</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">addsym</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">sym</span>, <span class="ruby-identifier">ptr</span>)
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span> = <span class="ruby-identifier">table</span>[<span class="ruby-identifier">sym</span>]
    <span class="ruby-identifier">table</span>[<span class="ruby-identifier">sym</span>] = <span class="ruby-identifier">s</span> = <span class="ruby-constant">ISet</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">s</span>.<span class="ruby-identifier">add</span> <span class="ruby-identifier">ptr</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-check_useless" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">check_useless</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="check_useless-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 586</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">check_useless</span>
  <span class="ruby-identifier">used</span> = []
  <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">each_reduce</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">act</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">act</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">act</span>.<span class="ruby-identifier">refn</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">act</span>.<span class="ruby-identifier">rule</span>.<span class="ruby-identifier">useless</span> = <span class="ruby-keyword">true</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">t</span> = <span class="ruby-identifier">act</span>.<span class="ruby-identifier">rule</span>.<span class="ruby-identifier">target</span>
      <span class="ruby-identifier">used</span>[<span class="ruby-identifier">t</span>.<span class="ruby-identifier">ident</span>] = <span class="ruby-identifier">t</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@symboltable</span>.<span class="ruby-identifier">nt_base</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-ivar">@symboltable</span>.<span class="ruby-identifier">nt_max</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">used</span>[<span class="ruby-identifier">n</span>]
      <span class="ruby-ivar">@symboltable</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">useless</span> = <span class="ruby-keyword">true</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compute_dfa" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compute_dfa</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="compute_dfa-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 206</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compute_dfa</span>
  <span class="ruby-identifier">la</span> = <span class="ruby-identifier">lookahead</span>()
  <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">state</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">state</span>.<span class="ruby-identifier">la</span> = <span class="ruby-identifier">la</span>
    <span class="ruby-identifier">resolve</span> <span class="ruby-identifier">state</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">set_accept</span>
  <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">state</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">pack</span> <span class="ruby-identifier">state</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">check_useless</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compute_nfa" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compute_nfa</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="compute_nfa-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 111</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compute_nfa</span>
  <span class="ruby-ivar">@grammar</span>.<span class="ruby-identifier">init</span>
  <span class="ruby-comment"># add state 0</span>
  <span class="ruby-identifier">core_to_state</span>  [ <span class="ruby-ivar">@grammar</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">ptrs</span>[<span class="ruby-value">0</span>] ]
  <span class="ruby-comment"># generate LALR states</span>
  <span class="ruby-identifier">cur</span> = <span class="ruby-value">0</span>
  <span class="ruby-ivar">@gotos</span> = []
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">cur</span> <span class="ruby-operator">&lt;</span> <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">size</span>
    <span class="ruby-identifier">generate_states</span> <span class="ruby-ivar">@states</span>[<span class="ruby-identifier">cur</span>]   <span class="ruby-comment"># state is added here</span>
    <span class="ruby-identifier">cur</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">init</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-core_to_state" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">core_to_state</span><span
                                class="method-args">(core)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="core_to_state-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 161</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">core_to_state</span>(<span class="ruby-identifier">core</span>)
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># convert CORE to a State object.</span>
  <span class="ruby-comment"># If matching state does not exist, create it and add to the table.</span>
  <span class="ruby-comment">#</span>

  <span class="ruby-identifier">k</span> = <span class="ruby-identifier">fingerprint</span>(<span class="ruby-identifier">core</span>)
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">dest</span> = <span class="ruby-ivar">@statecache</span>[<span class="ruby-identifier">k</span>]
    <span class="ruby-comment"># not registered yet</span>
    <span class="ruby-identifier">dest</span> = <span class="ruby-constant">State</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@states</span>.<span class="ruby-identifier">size</span>, <span class="ruby-identifier">core</span>)
    <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">dest</span>

    <span class="ruby-ivar">@statecache</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">dest</span>

    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;core_to_state: create state   ID #{dest.ident}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_state</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_state</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;core_to_state: dest is cached ID #{dest.ident}&quot;</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;core_to_state: dest core #{dest.core.join(&#39; &#39;)}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">dest</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-create_tmap" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">create_tmap</span><span
                                class="method-args">(size)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="create_tmap-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 313</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">create_tmap</span>(<span class="ruby-identifier">size</span>)
  <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">size</span>, <span class="ruby-value">0</span>)   <span class="ruby-comment"># use Integer as bitmap</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-digraph" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">digraph</span><span
                                class="method-args">(map, relation)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="digraph-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 348</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">digraph</span>(<span class="ruby-identifier">map</span>, <span class="ruby-identifier">relation</span>)
  <span class="ruby-identifier">n</span> = <span class="ruby-identifier">relation</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-identifier">index</span>    = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">n</span>, <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">vertices</span> = []
  <span class="ruby-ivar">@infinity</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>

  <span class="ruby-identifier">index</span>.<span class="ruby-identifier">each_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">index</span>[<span class="ruby-identifier">i</span>] <span class="ruby-keyword">and</span> <span class="ruby-identifier">relation</span>[<span class="ruby-identifier">i</span>]
      <span class="ruby-identifier">traverse</span> <span class="ruby-identifier">i</span>, <span class="ruby-identifier">index</span>, <span class="ruby-identifier">vertices</span>, <span class="ruby-identifier">map</span>, <span class="ruby-identifier">relation</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-do_resolve_sr" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">do_resolve_sr</span><span
                                class="method-args">(stok, rtok)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="do_resolve_sr-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 523</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">do_resolve_sr</span>(<span class="ruby-identifier">stok</span>, <span class="ruby-identifier">rtok</span>)
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;resolve_sr: s/r conflict: rtok=#{rtok}, stok=#{stok}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_prec</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">rtok</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">rtok</span>.<span class="ruby-identifier">precedence</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;resolve_sr: no prec for #{rtok}(R)&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_prec</span>
    <span class="ruby-keyword">return</span> <span class="ruby-value">:CantResolve</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">rprec</span> = <span class="ruby-identifier">rtok</span>.<span class="ruby-identifier">precedence</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">stok</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">stok</span>.<span class="ruby-identifier">precedence</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;resolve_sr: no prec for #{stok}(S)&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_prec</span>
    <span class="ruby-keyword">return</span> <span class="ruby-value">:CantResolve</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">sprec</span> = <span class="ruby-identifier">stok</span>.<span class="ruby-identifier">precedence</span>

  <span class="ruby-identifier">ret</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">rprec</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">sprec</span>
          <span class="ruby-constant">ASSOC</span>[<span class="ruby-identifier">rtok</span>.<span class="ruby-identifier">assoc</span>] <span class="ruby-keyword">or</span>
              <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;racc: fatal: #{rtok}.assoc is not Left/Right/Nonassoc&quot;</span>
        <span class="ruby-keyword">else</span>
          (<span class="ruby-identifier">rprec</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">sprec</span>) <span class="ruby-operator">?</span> (<span class="ruby-value">:Reduce</span>) <span class="ruby-operator">:</span> (<span class="ruby-value">:Shift</span>)
        <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;resolve_sr: resolved as #{ret.id2name}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_prec</span>
  <span class="ruby-identifier">ret</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_t" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_t</span><span
                                class="method-args">(tbl, set) { |tbl| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="each_t-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 422</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_t</span>(<span class="ruby-identifier">tbl</span>, <span class="ruby-identifier">set</span>)
  <span class="ruby-value">0</span>.<span class="ruby-identifier">upto</span>( <span class="ruby-identifier">set</span>.<span class="ruby-identifier">size</span> ) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    (<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">7</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ii</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">set</span>[<span class="ruby-identifier">idx</span> = <span class="ruby-identifier">i</span> <span class="ruby-operator">*</span> <span class="ruby-value">8</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">ii</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
        <span class="ruby-keyword">yield</span> <span class="ruby-identifier">tbl</span>[<span class="ruby-identifier">idx</span>]
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fingerprint" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fingerprint</span><span
                                class="method-args">(arr)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="fingerprint-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 186</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fingerprint</span>(<span class="ruby-identifier">arr</span>)
  <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">ident</span> }.<span class="ruby-identifier">pack</span>(<span class="ruby-string">&#39;L*&#39;</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-generate_states" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">generate_states</span><span
                                class="method-args">(state)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="generate_states-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 125</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">generate_states</span>(<span class="ruby-identifier">state</span>)
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;dstate: #{state}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_state</span>

  <span class="ruby-identifier">table</span> = {}
  <span class="ruby-identifier">state</span>.<span class="ruby-identifier">closure</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ptr</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">sym</span> = <span class="ruby-identifier">ptr</span>.<span class="ruby-identifier">dereference</span>
      <span class="ruby-identifier">addsym</span> <span class="ruby-identifier">table</span>, <span class="ruby-identifier">sym</span>, <span class="ruby-identifier">ptr</span>.<span class="ruby-identifier">next</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">table</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sym</span>, <span class="ruby-identifier">core</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;dstate: sym=#{sym} ncore=#{core}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_state</span>

    <span class="ruby-identifier">dest</span> = <span class="ruby-identifier">core_to_state</span>(<span class="ruby-identifier">core</span>.<span class="ruby-identifier">to_a</span>)
    <span class="ruby-identifier">state</span>.<span class="ruby-identifier">goto_table</span>[<span class="ruby-identifier">sym</span>] = <span class="ruby-identifier">dest</span>
    <span class="ruby-identifier">id</span> = <span class="ruby-identifier">sym</span>.<span class="ruby-identifier">nonterminal?</span>() <span class="ruby-operator">?</span> <span class="ruby-ivar">@gotos</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">g</span> = <span class="ruby-constant">Goto</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">sym</span>, <span class="ruby-identifier">state</span>, <span class="ruby-identifier">dest</span>)
    <span class="ruby-ivar">@gotos</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">g</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">sym</span>.<span class="ruby-identifier">nonterminal?</span>
    <span class="ruby-identifier">state</span>.<span class="ruby-identifier">gotos</span>[<span class="ruby-identifier">sym</span>] = <span class="ruby-identifier">g</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;dstate: #{state.ident} --#{sym}--&gt; #{dest.ident}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_state</span>

    <span class="ruby-comment"># check infinite recursion</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">state</span>.<span class="ruby-identifier">ident</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">dest</span>.<span class="ruby-identifier">ident</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">state</span>.<span class="ruby-identifier">closure</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">CompileError</span>,
          <span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;Infinite recursion: state %d, with rule %d&quot;</span>,
                  <span class="ruby-identifier">state</span>.<span class="ruby-identifier">ident</span>, <span class="ruby-identifier">state</span>.<span class="ruby-identifier">ptrs</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">rule</span>.<span class="ruby-identifier">ident</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-lookahead" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">lookahead</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="lookahead-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 219</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">lookahead</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># lookahead algorithm ver.3 -- from bison 1.26</span>
  <span class="ruby-comment">#</span>

  <span class="ruby-identifier">gotos</span> = <span class="ruby-ivar">@gotos</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_la</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;\n--- goto ---&quot;</span>
    <span class="ruby-identifier">gotos</span>.<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">g</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-identifier">i</span>, <span class="ruby-string">&#39; &#39;</span>; <span class="ruby-identifier">p</span> <span class="ruby-identifier">g</span> }
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">### initialize_LA()</span>
  <span class="ruby-comment">### set_goto_map()</span>
  <span class="ruby-identifier">la_rules</span> = []
  <span class="ruby-ivar">@states</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">state</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">state</span>.<span class="ruby-identifier">check_la</span> <span class="ruby-identifier">la_rules</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">### initialize_F()</span>
  <span class="ruby-identifier">f</span>     = <span class="ruby-identifier">create_tmap</span>(<span class="ruby-identifier">gotos</span>.<span class="ruby-identifier">size</span>)
  <span class="ruby-identifier">reads</span> = []
  <span class="ruby-identifier">edge</span>  = []
  <span class="ruby-identifier">gotos</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">goto</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">goto</span>.<span class="ruby-identifier">to_state</span>.<span class="ruby-identifier">goto_table</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span>, <span class="ruby-identifier">st</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">terminal?</span>
        <span class="ruby-identifier">f</span>[<span class="ruby-identifier">goto</span>.<span class="ruby-identifier">ident</span>] <span class="ruby-operator">|=</span> (<span class="ruby-value">1</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">ident</span>)
      <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">nullable?</span>
        <span class="ruby-identifier">edge</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">goto</span>.<span class="ruby-identifier">to_state</span>.<span class="ruby-identifier">gotos</span>[<span class="ruby-identifier">t</span>].<span class="ruby-identifier">ident</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">edge</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-identifier">reads</span>.<span class="ruby-identifier">push</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">reads</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">edge</span>
      <span class="ruby-identifier">edge</span> = []
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">digraph</span> <span class="ruby-identifier">f</span>, <span class="ruby-identifier">reads</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_la</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;\n--- F1 (reads) ---&quot;</span>
    <span class="ruby-identifier">print_tab</span> <span class="ruby-identifier">gotos</span>, <span class="ruby-identifier">reads</span>, <span class="ruby-identifier">f</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">### build_relations()</span>
  <span class="ruby-comment">### compute_FOLLOWS</span>
  <span class="ruby-identifier">path</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">edge</span> = []
  <span class="ruby-identifier">lookback</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">la_rules</span>.<span class="ruby-identifier">size</span>, <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">includes</span> = []
  <span class="ruby-identifier">gotos</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">goto</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">goto</span>.<span class="ruby-identifier">symbol</span>.<span class="ruby-identifier">heads</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ptr</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">path</span> = <span class="ruby-identifier">record_path</span>(<span class="ruby-identifier">goto</span>.<span class="ruby-identifier">from_state</span>, <span class="ruby-identifier">ptr</span>.<span class="ruby-identifier">rule</span>)
      <span class="ruby-identifier">lastgoto</span> = <span class="ruby-identifier">path</span>.<span class="ruby-identifier">last</span>
      <span class="ruby-identifier">st</span> = <span class="ruby-identifier">lastgoto</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">lastgoto</span>.<span class="ruby-identifier">to_state</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">goto</span>.<span class="ruby-identifier">from_state</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">st</span>.<span class="ruby-identifier">conflict?</span>
        <span class="ruby-identifier">addrel</span> <span class="ruby-identifier">lookback</span>, <span class="ruby-identifier">st</span>.<span class="ruby-identifier">rruleid</span>(<span class="ruby-identifier">ptr</span>.<span class="ruby-identifier">rule</span>), <span class="ruby-identifier">goto</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">path</span>.<span class="ruby-identifier">reverse_each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">g</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span>     <span class="ruby-identifier">g</span>.<span class="ruby-identifier">symbol</span>.<span class="ruby-identifier">terminal?</span>
        <span class="ruby-identifier">edge</span>.<span class="ruby-identifier">push</span>    <span class="ruby-identifier">g</span>.<span class="ruby-identifier">ident</span>
        <span class="ruby-keyword">break</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">g</span>.<span class="ruby-identifier">symbol</span>.<span class="ruby-identifier">nullable?</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">edge</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-identifier">includes</span>.<span class="ruby-identifier">push</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">includes</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">edge</span>
      <span class="ruby-identifier">edge</span> = []
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">includes</span> = <span class="ruby-identifier">transpose</span>(<span class="ruby-identifier">includes</span>)
  <span class="ruby-identifier">digraph</span> <span class="ruby-identifier">f</span>, <span class="ruby-identifier">includes</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_la</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;\n--- F2 (includes) ---&quot;</span>
    <span class="ruby-identifier">print_tab</span> <span class="ruby-identifier">gotos</span>, <span class="ruby-identifier">includes</span>, <span class="ruby-identifier">f</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment">### compute_lookaheads</span>
  <span class="ruby-identifier">la</span> = <span class="ruby-identifier">create_tmap</span>(<span class="ruby-identifier">la_rules</span>.<span class="ruby-identifier">size</span>)
  <span class="ruby-identifier">lookback</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">arr</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">arr</span>
      <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">g</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">la</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">|=</span> <span class="ruby-identifier">f</span>[<span class="ruby-identifier">g</span>.<span class="ruby-identifier">ident</span>]
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@d_la</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;\n--- LA (lookback) ---&quot;</span>
    <span class="ruby-identifier">print_tab</span> <span class="ruby-identifier">la_rules</span>, <span class="ruby-identifier">lookback</span>, <span class="ruby-identifier">la</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">la</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pack" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">pack</span><span
                                class="method-args">(state)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="pack-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 564</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">pack</span>(<span class="ruby-identifier">state</span>)
  <span class="ruby-comment">### find most frequently used reduce rule</span>
  <span class="ruby-identifier">act</span> = <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>
  <span class="ruby-identifier">arr</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grammar</span>.<span class="ruby-identifier">size</span>, <span class="ruby-value">0</span>)
  <span class="ruby-identifier">act</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span>, <span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">arr</span>[<span class="ruby-identifier">a</span>.<span class="ruby-identifier">ruleid</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>  <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Reduce</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">i</span> = <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">max</span>
  <span class="ruby-identifier">s</span> = (<span class="ruby-identifier">i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">i</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>

  <span class="ruby-comment">### set &amp; delete default action</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>
    <span class="ruby-identifier">r</span> = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">reduce</span>(<span class="ruby-identifier">s</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">state</span>.<span class="ruby-identifier">defact</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">state</span>.<span class="ruby-identifier">defact</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">r</span>
      <span class="ruby-identifier">act</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">t</span>, <span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">r</span> }
      <span class="ruby-identifier">state</span>.<span class="ruby-identifier">defact</span> = <span class="ruby-identifier">r</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">state</span>.<span class="ruby-identifier">defact</span> <span class="ruby-operator">||=</span> <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">error</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-print_atab" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">print_atab</span><span
                                class="method-args">(idx, tab)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>for debug</p>

                              <div class="method-source-code" id="print_atab-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 390</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">print_atab</span>(<span class="ruby-identifier">idx</span>, <span class="ruby-identifier">tab</span>)
  <span class="ruby-identifier">tab</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span>,<span class="ruby-identifier">ii</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">printf</span> <span class="ruby-string">&#39;%-20s&#39;</span>, <span class="ruby-identifier">idx</span>[<span class="ruby-identifier">ii</span>].<span class="ruby-identifier">inspect</span>
    <span class="ruby-identifier">p</span> <span class="ruby-identifier">i</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-print_tab" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">print_tab</span><span
                                class="method-args">(idx, rel, tab)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="print_tab-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 397</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">print_tab</span>(<span class="ruby-identifier">idx</span>, <span class="ruby-identifier">rel</span>, <span class="ruby-identifier">tab</span>)
  <span class="ruby-identifier">tab</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">bin</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">print</span> <span class="ruby-identifier">i</span>, <span class="ruby-string">&#39; &#39;</span>, <span class="ruby-identifier">idx</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">inspect</span>, <span class="ruby-string">&#39; &lt;&lt; &#39;</span>; <span class="ruby-identifier">p</span> <span class="ruby-identifier">rel</span>[<span class="ruby-identifier">i</span>]
    <span class="ruby-identifier">print</span> <span class="ruby-string">&#39;  &#39;</span>
    <span class="ruby-identifier">each_t</span>(<span class="ruby-ivar">@symboltable</span>, <span class="ruby-identifier">bin</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-string">&#39; &#39;</span>, <span class="ruby-identifier">t</span> }
    <span class="ruby-identifier">puts</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-print_tab_i" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">print_tab_i</span><span
                                class="method-args">(idx, rel, tab, i)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>for debug</p>

                              <div class="method-source-code" id="print_tab_i-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 407</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">print_tab_i</span>(<span class="ruby-identifier">idx</span>, <span class="ruby-identifier">rel</span>, <span class="ruby-identifier">tab</span>, <span class="ruby-identifier">i</span>)
  <span class="ruby-identifier">bin</span> = <span class="ruby-identifier">tab</span>[<span class="ruby-identifier">i</span>]
  <span class="ruby-identifier">print</span> <span class="ruby-identifier">i</span>, <span class="ruby-string">&#39; &#39;</span>, <span class="ruby-identifier">idx</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">inspect</span>, <span class="ruby-string">&#39; &lt;&lt; &#39;</span>; <span class="ruby-identifier">p</span> <span class="ruby-identifier">rel</span>[<span class="ruby-identifier">i</span>]
  <span class="ruby-identifier">print</span> <span class="ruby-string">&#39;  &#39;</span>
  <span class="ruby-identifier">each_t</span>(<span class="ruby-ivar">@symboltable</span>, <span class="ruby-identifier">bin</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-string">&#39; &#39;</span>, <span class="ruby-identifier">t</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-printb" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">printb</span><span
                                class="method-args">(i)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>for debug</p>

                              <div class="method-source-code" id="printb-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 415</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">printb</span>(<span class="ruby-identifier">i</span>)
  <span class="ruby-identifier">each_t</span>(<span class="ruby-ivar">@symboltable</span>, <span class="ruby-identifier">i</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">print</span> <span class="ruby-identifier">t</span>, <span class="ruby-string">&#39; &#39;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">puts</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-record_path" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">record_path</span><span
                                class="method-args">(begst, rule)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="record_path-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 325</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">record_path</span>(<span class="ruby-identifier">begst</span>, <span class="ruby-identifier">rule</span>)
  <span class="ruby-identifier">st</span> = <span class="ruby-identifier">begst</span>
  <span class="ruby-identifier">path</span> = []
  <span class="ruby-identifier">rule</span>.<span class="ruby-identifier">symbols</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">goto</span> = <span class="ruby-identifier">st</span>.<span class="ruby-identifier">gotos</span>[<span class="ruby-identifier">t</span>]
    <span class="ruby-identifier">path</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">goto</span>
    <span class="ruby-identifier">st</span> = <span class="ruby-identifier">goto</span>.<span class="ruby-identifier">to_state</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">path</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-resolve" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">resolve</span><span
                                class="method-args">(state)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>resolve</p>

                              <div class="method-source-code" id="resolve-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 436</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">resolve</span>(<span class="ruby-identifier">state</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">state</span>.<span class="ruby-identifier">conflict?</span>
    <span class="ruby-identifier">resolve_rr</span> <span class="ruby-identifier">state</span>, <span class="ruby-identifier">state</span>.<span class="ruby-identifier">ritems</span>
    <span class="ruby-identifier">resolve_sr</span> <span class="ruby-identifier">state</span>, <span class="ruby-identifier">state</span>.<span class="ruby-identifier">stokens</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">state</span>.<span class="ruby-identifier">rrules</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-comment"># shift</span>
      <span class="ruby-identifier">state</span>.<span class="ruby-identifier">stokens</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">t</span>] = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">shift</span>(<span class="ruby-identifier">state</span>.<span class="ruby-identifier">goto_table</span>[<span class="ruby-identifier">t</span>])
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-comment"># reduce</span>
      <span class="ruby-identifier">state</span>.<span class="ruby-identifier">defact</span> = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">reduce</span>(<span class="ruby-identifier">state</span>.<span class="ruby-identifier">rrules</span>[<span class="ruby-value">0</span>])
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-resolve_rr" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">resolve_rr</span><span
                                class="method-args">(state, r)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="resolve_rr-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 453</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">resolve_rr</span>(<span class="ruby-identifier">state</span>, <span class="ruby-identifier">r</span>)
  <span class="ruby-identifier">r</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">item</span>.<span class="ruby-identifier">each_la</span>(<span class="ruby-ivar">@symboltable</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">act</span> = <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">t</span>]
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">act</span>
        <span class="ruby-keyword">unless</span> <span class="ruby-identifier">act</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Reduce</span>)
          <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;racc: fatal: #{act.class} in action table&quot;</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-comment"># Cannot resolve R/R conflict (on t).</span>
        <span class="ruby-comment"># Reduce with upper rule as default.</span>
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">rr_conflict</span> <span class="ruby-identifier">act</span>.<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">item</span>.<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">t</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-comment"># No conflict.</span>
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">t</span>] = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">reduce</span>(<span class="ruby-identifier">item</span>.<span class="ruby-identifier">rule</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-resolve_sr" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">resolve_sr</span><span
                                class="method-args">(state, s)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="resolve_sr-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 472</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">resolve_sr</span>(<span class="ruby-identifier">state</span>, <span class="ruby-identifier">s</span>)
  <span class="ruby-identifier">s</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">stok</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">goto</span> = <span class="ruby-identifier">state</span>.<span class="ruby-identifier">goto_table</span>[<span class="ruby-identifier">stok</span>]
    <span class="ruby-identifier">act</span> = <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">stok</span>]

    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">act</span>
      <span class="ruby-comment"># no conflict</span>
      <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">stok</span>] = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">shift</span>(<span class="ruby-identifier">goto</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">unless</span> <span class="ruby-identifier">act</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Reduce</span>)
        <span class="ruby-identifier">puts</span> <span class="ruby-string">&#39;DEBUG -------------------------------&#39;</span>
        <span class="ruby-identifier">p</span> <span class="ruby-identifier">stok</span>
        <span class="ruby-identifier">p</span> <span class="ruby-identifier">act</span>
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">print</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">inspect</span>, <span class="ruby-string">&#39; &#39;</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">inspect</span>, <span class="ruby-string">&quot;\n&quot;</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;racc: fatal: #{act.class} in action table&quot;</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-comment"># conflict on stok</span>

      <span class="ruby-identifier">rtok</span> = <span class="ruby-identifier">act</span>.<span class="ruby-identifier">rule</span>.<span class="ruby-identifier">precedence</span>
      <span class="ruby-keyword">case</span> <span class="ruby-identifier">do_resolve_sr</span>(<span class="ruby-identifier">stok</span>, <span class="ruby-identifier">rtok</span>)
      <span class="ruby-keyword">when</span> <span class="ruby-value">:Reduce</span>
        <span class="ruby-comment"># action is already set</span>

      <span class="ruby-keyword">when</span> <span class="ruby-value">:Shift</span>
        <span class="ruby-comment"># overwrite</span>
        <span class="ruby-identifier">act</span>.<span class="ruby-identifier">decref</span>
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">stok</span>] = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">shift</span>(<span class="ruby-identifier">goto</span>)

      <span class="ruby-keyword">when</span> <span class="ruby-value">:Error</span>
        <span class="ruby-identifier">act</span>.<span class="ruby-identifier">decref</span>
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">stok</span>] = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">error</span>

      <span class="ruby-keyword">when</span> <span class="ruby-value">:CantResolve</span>
        <span class="ruby-comment"># shift as default</span>
        <span class="ruby-identifier">act</span>.<span class="ruby-identifier">decref</span>
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">stok</span>] = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">shift</span>(<span class="ruby-identifier">goto</span>)
        <span class="ruby-identifier">state</span>.<span class="ruby-identifier">sr_conflict</span> <span class="ruby-identifier">stok</span>, <span class="ruby-identifier">act</span>.<span class="ruby-identifier">rule</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_accept" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_accept</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>complete</p>

                              <div class="method-source-code" id="set_accept-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 553</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_accept</span>
  <span class="ruby-identifier">anch</span> = <span class="ruby-ivar">@symboltable</span>.<span class="ruby-identifier">anchor</span>
  <span class="ruby-identifier">init_state</span> = <span class="ruby-ivar">@states</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">goto_table</span>[<span class="ruby-ivar">@grammar</span>.<span class="ruby-identifier">start</span>]
  <span class="ruby-identifier">targ_state</span> = <span class="ruby-identifier">init_state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">anch</span>].<span class="ruby-identifier">goto_state</span>
  <span class="ruby-identifier">acc_state</span>  = <span class="ruby-identifier">targ_state</span>.<span class="ruby-identifier">action</span>[<span class="ruby-identifier">anch</span>].<span class="ruby-identifier">goto_state</span>

  <span class="ruby-identifier">acc_state</span>.<span class="ruby-identifier">action</span>.<span class="ruby-identifier">clear</span>
  <span class="ruby-identifier">acc_state</span>.<span class="ruby-identifier">goto_table</span>.<span class="ruby-identifier">clear</span>
  <span class="ruby-identifier">acc_state</span>.<span class="ruby-identifier">defact</span> = <span class="ruby-ivar">@actions</span>.<span class="ruby-identifier">accept</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-transpose" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">transpose</span><span
                                class="method-args">(rel)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="transpose-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 336</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">transpose</span>(<span class="ruby-identifier">rel</span>)
  <span class="ruby-identifier">new</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rel</span>.<span class="ruby-identifier">size</span>, <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">rel</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">arr</span>, <span class="ruby-identifier">idx</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">arr</span>
      <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">addrel</span> <span class="ruby-identifier">new</span>, <span class="ruby-identifier">i</span>, <span class="ruby-identifier">idx</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">new</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-traverse" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">traverse</span><span
                                class="method-args">(i, index, vertices, map, relation)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="traverse-source">
            <pre><span class="ruby-comment"># File racc-1.7.1/lib/racc/state.rb, line 361</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">traverse</span>(<span class="ruby-identifier">i</span>, <span class="ruby-identifier">index</span>, <span class="ruby-identifier">vertices</span>, <span class="ruby-identifier">map</span>, <span class="ruby-identifier">relation</span>)
  <span class="ruby-identifier">vertices</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">i</span>
  <span class="ruby-identifier">index</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">height</span> = <span class="ruby-identifier">vertices</span>.<span class="ruby-identifier">size</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">rp</span> = <span class="ruby-identifier">relation</span>[<span class="ruby-identifier">i</span>]
    <span class="ruby-identifier">rp</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">proci</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">unless</span> <span class="ruby-identifier">index</span>[<span class="ruby-identifier">proci</span>]
        <span class="ruby-identifier">traverse</span> <span class="ruby-identifier">proci</span>, <span class="ruby-identifier">index</span>, <span class="ruby-identifier">vertices</span>, <span class="ruby-identifier">map</span>, <span class="ruby-identifier">relation</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">index</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">index</span>[<span class="ruby-identifier">proci</span>]
        <span class="ruby-comment"># circulative recursion !!!</span>
        <span class="ruby-identifier">index</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">index</span>[<span class="ruby-identifier">proci</span>]
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">map</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">|=</span> <span class="ruby-identifier">map</span>[<span class="ruby-identifier">proci</span>]
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">index</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">height</span>
    <span class="ruby-keyword">while</span> <span class="ruby-keyword">true</span>
      <span class="ruby-identifier">proci</span> = <span class="ruby-identifier">vertices</span>.<span class="ruby-identifier">pop</span>
      <span class="ruby-identifier">index</span>[<span class="ruby-identifier">proci</span>] = <span class="ruby-ivar">@infinity</span>
      <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">proci</span>

      <span class="ruby-identifier">map</span>[<span class="ruby-identifier">proci</span>] <span class="ruby-operator">|=</span> <span class="ruby-identifier">map</span>[<span class="ruby-identifier">i</span>]
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

